import UserDogModel from "../model/UserDogModel";



export default class UserData {

    private static _instance: UserData = null;
    public static getInstance(): UserData {
        if (!this._instance) {
            this._instance = new UserData();
        }
        return this._instance;
    }

    //初始化数据
    init(data, callback = null) {
        // for (let key in data) {
        //     this[key] = data[key];
        // }
        callback && callback();
    }

    //保存数据
    public saveData() {
        let userData = {};
        console.log("存档数据", userData);
        cc.sys.localStorage.setItem('userData', JSON.stringify(userData));
    }

    private _data = {
        //登录时间
        _loginTime: 0,
        //在线时间
        _onLineTime: 0,
        //声音大小
        _musicVolume: 0.5,
        //音效大小
        _effectVolume: 0.5,
        //出生数据
        _birthData: null,
        //天气数据
        _weatherDataList: {},
        //事件
        _eventRecord: [],
        //选择
        _chooseRecord: {}
    }


    set loginTime(val) {
        this._data._loginTime = val;
    }
    get loginTime() {
        return this._data._loginTime;
    }


    set onLineTime(val) {
        this._data._onLineTime = val;
    }
    get onLineTime() {
        return this._data._onLineTime;
    }


    set musicVolume(val) {
        this._data._musicVolume = val;
    }
    get musicVolume() {
        return this._data._musicVolume;
    }


    set effectVolume(val) {
        this._data._effectVolume = val;
    }
    get effectVolume() {
        return this._data._effectVolume;
    }


    set birthData(val) {
        this._data._birthData = val;
    }
    get birthData(): UserDogModel {
        return this._data._birthData;
    }


    set weatherDataList(val) {
        this._data._weatherDataList = val;
    }
    get weatherDataList() {
        return this._data._weatherDataList;
    }

    set eventRecord(val) {
        this._data._eventRecord = val;
    }
    get eventRecord() {
        return this._data._eventRecord;
    }

    set chooseRecord(val) {
        this._data._chooseRecord = val;
    }
    get chooseRecord() {
        return this._data._chooseRecord;
    }


}
window['UserData'] = UserData.getInstance();

